import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
/* Layout */
import Layout from '@/layout'
/* const roles = ['visitor', 'manager', 'finance', 'readOnly', 'advManager'] */
/*
      // const roles=['系列管理员','账号财务','系列只读']
        团队管理员：visitor:拥有所有权限及路由
        广告管理员：advManager: 管理团队中所有广告系列组和广告系列，但没有管理团队（邀请成员、编辑成员、移除成员、解散团队、上传团队头像、更改团队名称）和管理结算（充值、提现）权限
        系列管理员：manager:除了(财务+绑定秘钥+编辑广告系列组)外的所有权限+路由
        账号财务：finance:除了公共页面之外 只能进入财务页面
        账号只读：readOnly:除了公共页面之外，只能进入数据概览页面&&只有查询及导出功能
		    系列只读：：campaignsReadOnly：同上
      */




/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   如果设置 true, 不会显示在侧边栏(默认为false)
 * alwaysShow: true               如果设置 true, 永远显示在侧边栏根菜单
 *
 *                                如果没有设置alwaysShow，当item有多个子路由时，
 *                                它将变成嵌套模式，否则不会显示根菜单
 *
 * redirect: noRedirect           如果设置noRedirect将不会在面包屑中重定向
 * name:'router-name'              这个名字被<keep-alive>使用(必须设置!!)
 * meta : {
    roles: ['admin','editor']    控制页面角色(可以设置多个角色) 如果注释此字段则默认任何角色都能进入
    title: 'title'               名称显示在侧边栏和breadcrumb(推荐设置)
    icon: 'svg-name'/'el-icon-x'  图标显示在侧边栏
    breadcrumb: false            如果图标设置为false，项目将隐藏在breadcrumb(默认为true)显示在侧边栏
    activeMenu: '/example/list'  如果设置路径，侧边栏将突出显示您设置的路径
    * changeCurrency:true,        如果设置为true,则可以切换 海外||中国大陆
    * hideenCurrency:true        如果设置为true,则切换“海外||中国大陆”按钮隐藏
  }
 */

/**
 * 固定路由
 * 没有权限要求的基本页面
 * 所有角色都可以访问
 */
export const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    name: 'Login',
    title: '登录及注册'
  },
  {
    path: '/',
    redirect: '/home',
    component: () => import('@/views/home/index'),

  },
  {
    path: '/home',
    component: () => import('@/views/home/index'),
    hidden: true,
    title: '首页'
  },
  {
    path: '/account',
    component: () => import('@/views/account/index'),
    hidden: true,
    title: '3YData协议'
  },
  {
    path: '/news-list',
    name: 'newsList',
    title: '文章列表',
    component: () => import('@/views/news/news-list/index'),
    hidden: true
  },
  {
    path: '/news-details',
    name: 'newsDetaila',
    title: '文章详情',
    component: () => import('@/views/news/news-details/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },

]

/**
 * asyncRoutes
 * 需要根据用户角色动态加载的路由
 */
export const asyncRoutes = [{
    path: '/ad',
    component: Layout,
    redirect: 'ad/create',
    name: 'Ad',
    alwaysShow: true,
    meta: {
      title: '广告',
      icon: 'guang_gao',
      roles: ['manager', 'readOnly', 'advManager'],
    },
    children: [{
        path: 'create',
        name: 'Create',
        redirect: 'create/create-type',
        hidden: true,
        component: () => import('@/views/ad/create/index'),
        meta: {
          title: '创建广告',
          roles: ['manager','advManager', 'visitor', 'admin'],
        },
        children: [{
            path: 'create-type',
            name: 'Createtype',
            hidden: true,
            component: () => import('@/views/ad/create/create-type/index'),
            meta: {
              title: '投放模式选择',
              activeMenu: '/ad/create',
              keepAlive: true,
              changeCurrency: false,
              roles: ['manager','advManager', 'visitor', 'admin']
            }
          },
          {
            path: 'create-series',
            name: 'CreateSeries',
            hidden: true,
            component: () => import('@/views/ad/create/create-series/index'),
            meta: {
              title: '创建广告系列',
              activeMenu: '/ad/create',
              keepAlive: true,
              roles: ['manager','advManager', 'visitor', 'admin']
            }
          },
          {
            path: 'create-group',
            name: 'CreateGroup',
            hidden: true,
            component: () => import('@/views/ad/create/create-group/index'),
            meta: {
              title: '创建广告组',
              activeMenu: '/ad/create',
              icon: 'table',
              keepAlive: true,
              roles: ['manager','advManager', 'visitor', 'admin']
            }
          },
          {
            path: 'create-put',
            name: 'CreatePut',
            hidden: true,
            component: () => import('@/views/ad/create/create-put/index'),
            meta: {
              title: '支付并开始投放',
              activeMenu: '/ad/create',
              icon: 'table',
              keepAlive: false,
              roles: ['manager','advManager', 'visitor', 'admin']
            }
          }
        ]
      },
      {
        path: 'overview',
        name: 'Overview',
        redirect: 'overview/type-overview',
        component: () => import('@/views/ad/overview/index'),
        meta: {
          title: '数据概览',
          keepAlive: false,
        },
        children: [{
            path: 'type-overview',
            name: 'typeOverview',
            hidden: true,
            component: () => import('@/views/ad/overview/type-overview/index'),
            meta: {
              title: '投放模式概览',
              icon: 'table',
              keepAlive: false,
              activeMenu: '/ad/overview',
              changeCurrency: false,

            }
          },
          {
            path: 'series-overview',
            name: 'seriesOverview',
            hidden: true,
            component: () => import('@/views/ad/overview/series-overview/index'),
            meta: {
              title: '广告系列数据概览',
              icon: 'table',
              keepAlive: false,
              activeMenu: '/ad/overview',
              changeCurrency: false,
            }
          },
          {
            path: 'group-overview',
            name: 'groupOverview',
            hidden: true,
            component: () => import('@/views/ad/overview/group-overview/index'),
            meta: {
              title: '广告组数据概览',
              icon: 'table',
              keepAlive: false,
              activeMenu: '/ad/overview',
              changeCurrency: false,
            }
          }
        ]
      }
    ]
  },
  {
    path: '/tool',
    component: Layout,
    alwaysShow: true,
    /* hidden: true, */
    meta: {
      title: '工具',
      icon: 'tool',
      roles: ['manager','advManager']
    },
    children: [{
        path: 'wordicon',
        name: 'wordicon',
        /* hidden: true, */
        component: () => import('@/views/tool/word/index'),
        meta: {
          title: '关键词库',
          roles: ['manager','advManager']
        }
      },
      {
        path: 'wordDetail',
        name: 'wordDetail',
        hidden: true,
        component: () => import('@/views/tool/wordDetail/index'),
        meta: {
          title: '词库详情',
          activeMenu: '/tool/wordicon',
          roles: ['manager','advManager']
        }
      },
      // {
      //   path: 'openWord',
      //   name: 'openWord',
      //   /* hidden: true, */
      //   component: () => import('@/views/tool/openWord/index'),
      //   meta: {
      //     title: '智能拓词',
      //     roles: ['manager','advManager']
      //   }
      // },
      // {
      //   path: 'warning',
      //   name: 'warning',
      //   component: () => import('@/views/tool/warning/index'),
      //   meta: {
      //     title: '预警监控',
      //     roles: ['manager','advManager']
      //   }
      // },
    ]
  },
  {
    path: '/user',
    component: Layout,
    name: 'user',
    alwaysShow: true,
    meta: {
      title: '团队',
      icon: 'zhang_hao'
    },
    children: [
      {
        path: 'user_manager',
        name: 'user_manager',
        component: () => import('@/views/user/user-manager/index'),
        meta: {
          title: '团队管理',
          keepAlive: false,
          roles: ['manager', 'finance', 'readOnly', 'advManager']
        }
      },
      {
        path: 'zs_manager',
        name: 'zs_manager',
        component: () => import('@/views/user/zs-manager/index'),
        meta: {
          title: '证书管理',
          keepAlive: false,
          // changeCurrency:true,
          roles: ['visitor']
        }
      },
      {
        path: 'zs_bind',
        name: 'zs_bind',
        hidden: true,
        component: () => import('@/views/user/zs-manager/zs-bind'),
        meta: {
          title: '绑定证书',
          keepAlive: false,
          activeMenu: '/user/zs_manager',
          roles: ['visitor']
        }
      },
      {
        path: 'create_team',
        name: 'create_team',
        hidden: true,
        component: () => import('@/views/user/user-manager/create_team'),
        meta: {
          title: '创建团队',
          keepAlive: false,
          activeMenu: '/user/user_manager',
          // roles: ['visitor']
        }
      }
    ]
  },
  // 财务
  // {
  //   path: '/finance',
  //   component: Layout,
  //   name: 'finance',
  //   alwaysShow: true,
  //   // redirect: '/finance/index',
  //   meta: {
  //     title: '财务',
  //     icon: 'cai_wu',
  //     keepAlive: true
  //   },
  //   children: [{
  //     path: 'index',
  //     name: 'Finance',
  //     component: () => import('@/views/finance/index'),
  //     meta: {
  //       title: '财务中心',
  //       keepAlive: true,
  //       changeCurrency: false,
  //       roles: ['finance', 'manager', 'readOnly','advManager']
  //     }
  //   }]
  // },
  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',

  }
]

const createRouter = () => new Router({
  mode: 'hash', // require service support
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
